Be a bit more careful not to crash if the compiler doesn't support --crate-type metadata
authorNick Cameron <ncameron@mozilla.com>
Thu, 1 Dec 2016 22:25:55 +0000 (11:25 +1300)
committerNick Cameron <ncameron@mozilla.com>
Fri, 9 Dec 2016 19:08:52 +0000 (09:08 -1000)
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/util/toml.rs

index da6f538ce61b018fdf6b7361535945e912fa65c0..b44b3e025fd172995b8a2b5aef8426439693855d 100644 (file)
@@ -65,7 +65,7 @@ pub struct CompileOptions<'a> {
     pub target_rustc_args: Option<&'a [String]>,
 }
 
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Debug)]
 pub enum CompileMode {
     Test,
     Build,
index bb8176a6f0559b2973a751fdc6cb4a4bc27a5b28..f01c0b141ed5b9d8dfea05550d38236133bf8909 100644 (file)
@@ -174,13 +174,17 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                                       "RUSTFLAGS")?;
         let mut process = self.config.rustc()?.process();
         process.arg("-")
-               .arg("--crate-name").arg("_")
+               .arg("--crate-name").arg("___")
                .arg("--print=file-names")
                .args(&rustflags)
                .env_remove("RUST_LOG");
 
         for crate_type in crate_types {
-            process.arg("--crate-type").arg(crate_type);
+            // Here and below we'll skip the metadata crate-type because it is
+            // not supported by older compilers. We'll do this one manually.
+            if crate_type != "metadata" {
+                process.arg("--crate-type").arg(crate_type);
+            }
         }
         if kind == Kind::Target {
             process.arg("--target").arg(&self.target_triple());
@@ -204,31 +208,37 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         let mut map = HashMap::new();
         for crate_type in crate_types {
             let not_supported = error.lines().any(|line| {
-                line.contains("unsupported crate type") &&
-                    line.contains(crate_type)
+                (line.contains("unsupported crate type") ||
+                 line.contains("unknown crate type")) &&
+                line.contains(crate_type)
             });
             if not_supported {
-                if crate_type == "metadata" {
-                    bail!("compiler does not support `--crate-type metadata`, \
-                           cannot run `cargo check`.");
-                }
                 map.insert(crate_type.to_string(), None);
-                continue
+                continue;
+            }
+            if crate_type == "metadata" {
+                continue;
             }
             let line = match lines.next() {
                 Some(line) => line,
                 None => bail!("malformed output when learning about \
                                target-specific information from rustc"),
             };
-            let mut parts = line.trim().split('_');
+            let mut parts = line.trim().split("___");
             let prefix = parts.next().unwrap();
             let suffix = match parts.next() {
                 Some(part) => part,
                 None => bail!("output of --print=file-names has changed in \
                                the compiler, cannot parse"),
             };
-            map.insert(crate_type.to_string(),
-                       Some((prefix.to_string(), suffix.to_string())));
+
+            map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
+        }
+        // Manually handle the metadata case. If it is not supported by the
+        // compiler we'll error out elsewhere.
+        if crate_types.contains("metadata") {
+            map.insert("metadata".to_string(), Some(("lib".to_owned(), ".rmeta".to_owned())));
         }
 
         let cfg = if has_cfg {
index 7d47bcf928ef9c85e1b851859015b54fbc1facad..e670715d4ea4fee92d548348dab83f399e41d201 100644 (file)
@@ -1249,7 +1249,7 @@ fn build_profiles(profiles: &Option<TomlProfiles>) -> Profiles {
                    profiles.and_then(|p| p.doc.as_ref())),
         custom_build: Profile::default_custom_build(),
         check: merge(Profile::default_check(),
-                   profiles.and_then(|p| p.dev.as_ref())),
+                     profiles.and_then(|p| p.dev.as_ref())),
     };
     // The test/bench targets cannot have panic=abort because they'll all get
     // compiled with --test which requires the unwind runtime currently